import { fetchPost } from '../../../../utils/request'
import { message } from 'antd'

export const getCategoryList = async () => {
  const res = await fetchPost('/promotion/list/apps', {})
  if (res.code === 0) {
    return res.data.appList
  } else {
    message.error(res.msg)
    return []
  }
}

export const postFormData = async (data) => {
  const res = await fetchPost('/promotion/cost/save', data)
  return res.msg === 'SUCCESS'
}

export const updateFormData = async (data) => {
  const res = await fetchPost('/promotion/cost/update', data)
  return res.msg === 'SUCCESS'
}

export const getPromotionList = async (data, currentPage, pageSize) => {
  const res = await fetchPost(`/promotion/list?currentPage=${currentPage}&pageSize=${pageSize}`, data)
  if (res.code === 0) {
    return res
  } else {
    message.error(res.msg)
    return {}
  }
}

export const getFilterList = async (data) => {
  const res = await fetchPost(`/promotion/filter`, data)
  if (res.code === 0) {
    return res.data.list
  } else {
    message.error(res.msg)
    return []
  }
}

export const getFilteredProductList = async (appCode) => {
  const res = await fetchPost(`/promotion/list/products?app=${appCode}`)
  if (res.code === 0) {
    return res
  } else {
    message.error(res.msg)
    return []
  }
}

export const deleteData = async (data) => {
  const res = await fetchPost(`/promotion/delete?id=${data}`)
  return res.msg === 'SUCCESS'
}

export const getProductList = async () => {
  const res = await fetchPost('/admin/productCategory/list')
  if (res.code === 0) {
    return res.data.list
  } else {
    message.error(res.msg)
    return []
  }
}
